/* javascript for templates/views_statistics_admin/project_statistics.html */

function init_all_chart()
{
    init_all_bug_chart();
    $("#project-bug-types > a:eq(0)").click();
    $("#project-bug-trend > a:eq(0)").click();
}

/* 所有项目的BUG状况 */
function init_all_bug_chart()
{
    req = new Chujue_Request();
    req.url = "/admin/project-all-bug-chart";
    req.is_setmessage = false;
    req.ok_func = function(data) {
        $("#morris-all-bug-chart").empty();
        Morris.Bar({
            element: 'morris-all-bug-chart',
            data: data["records"],
            xkey: 'project_name',
            ykeys: ['bug_count'],
            labels: ['bug总数'],
            resize: true,
            // barRatio: 0.4,
            // xLabelAngle: 270,
        });
    };
    req.ajax_req();
}

/* 各个项目的BUG类型（状态，重要性）分类 */
function init_bug_types_chart(p_id)
{
    req_state = new Chujue_Request();
    req_state.url = "/admin/project-bug-state-chart";
    req_state.is_setmessage = false;
    req_state.send_data = {"project_id": p_id};
    req_state.ok_func = function(data) {
        $("#morris-bug-state-chart").empty();
        Morris.Donut({
            element: 'morris-bug-state-chart',
            data: data["records"],
        });
    };
    req_state.ajax_req();
    
    req_import = new Chujue_Request();
    req_import.url = "/admin/project-bug-import-chart";
    req_import.is_setmessage = false;
    req_import.send_data = {"project_id": p_id};
    req_import.ok_func = function(data) {
        $("#morris-bug-import-chart").empty();
        Morris.Donut({
            element: 'morris-bug-import-chart',
            data: data["records"],
        });
    };
    req_import.ajax_req();
    
}

/* 各个项目的BUG变化 */
function init_bug_change_chart(p_id)
{
    req = new Chujue_Request();
    req.url = "/admin/project-bug-change-chart";
    req.is_setmessage = false;
    req.send_data = {"project_id": p_id};
    req.ok_func = function(data) {
        $("#morris-bug-change-chart").empty();
        Morris.Line({
            element: 'morris-bug-change-chart',
            data: data["records"],
            xkey: 'date',
            ykeys: ['bug_count'],
            labels: ['bug数'],
            resize: true,
        });
    };
    req.ajax_req();
}

/* 「各项目bug分类」中切换项目 */
function bug_type_change_project(a, p_id)
{
    $("#project-bug-types > a").removeClass("active");
    $(a).addClass("active");

    init_bug_types_chart(p_id);
}

/* 「最近2周各项目bug变化」中切换项目  */
function bug_trend_change_project(a, p_id)
{
    $("#project-bug-trend > a").removeClass("active");
    $(a).addClass("active");

    init_bug_change_chart(p_id);
}

